#include <iostream>
#include <stdio.h>
#include <climits>
#include <string.h>

using namespace std;
//#define DEBUG

#define MAX_LEN 150 

char brackets[MAX_LEN];
int dp[MAX_LEN][MAX_LEN];
int path[MAX_LEN][MAX_LEN];//path[i][j] 表示当dp[i][j]最小时 [i:j]子串中需添加匹配的字符的位置

void InitDp() {
    memset(dp, 0, sizeof(dp));
    int len = strlen(brackets);
    for (int i = 0; i < len; ++i) {
                dp[i][i] = 1;
    }
}

#ifdef DEBUG
void PrintDp() {
    int len = strlen(brackets);
    for (int i = 0; i < len; ++i) {
        for (int j = 0; j < len; ++j) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
}
#endif

void PrintResult(int l, int r) {
    if (l > r) 
        return;
    if (l == r) {
        if (brackets[l] == '(' || brackets[l] == ')'){
            cout << "()";
        }
        else {
            cout << "[]";
        }
    }
    else if (path[l][r] == -1) {
        cout << brackets[l];
        PrintResult(l+1, r-1);
        cout << brackets[r];
    }
    else {
            PrintResult(l, path[l][r]);
            PrintResult(path[l][r]+1, r);
    }
}

void Process() {
    InitDp();
#ifdef DEBUG
    cout << brackets << endl;
    PrintDp();
#endif
    int len = strlen(brackets);
    for (int interval = 1; interval < len; interval++) {
        for (int i = 0; i + interval < len; ++i) {
            int j = i + interval;
            dp[i][j] = INT_MAX;
            if ((brackets[i] == '(' && brackets[j] == ')') || (brackets[i] == '[' && brackets[j] == ']')) {
                if (dp[i][j] > dp[i+1][j-1]) 
                    dp[i][j] = dp[i+1][j-1], path[i][j] = -1;
            }
            for (int k = i; k < j; k++) {
                if (dp[i][j] > dp[i][k] + dp[k+1][j])
                    dp[i][j] = dp[i][k] + dp[k+1][j], path[i][j] = k;
            }

        }
    }
#ifdef DEBUG
    PrintDp();
    cout << "++++++++"  << endl;
    for (int i = 0; i < len; ++i) {
        for (int j = 0; j < len; j++) {
            cout << path[i][j] << " ";
        }
        cout << endl;
    }
#endif

    PrintResult(0, len-1);
    cout << endl;

}

int main() {
    while(gets(brackets)) { //只能用gets，不能用cin，否则WA
        Process();
    }

    return 0;
}
